<?php

require_once 'facebook/facebook.php';

class SocialFacebook extends SocialAbstract
			   implements SocialInterface
{
	protected $_config = array();
	protected $_sdk;
	protected $_user;

	public function init()
	{
		if($this->_sdk !== null)
			return false;

		$this->_sdk = new Facebook($this->_config);

		$this->_user = $this->_sdk->getUser();

		if($this->_user === 0)
		{
			$loginUrl = $this->_sdk->getLoginUrl(array(
				'scope' => 'manage_pages,offline_access,publish_stream, read_stream'
			));

			echo $loginUrl; exit;
		}

		return true;
	}

	public function setConfig(array $config)
	{
		$this->_config = $config;

		return $this;
	}

	public function postToWall($title, $description, $link = '')
	{
		$this->init();

		$params = array(
			'message' => $title,
//			'caption' => $title,
			'link' => $link,
			'description' => $description
		);

		$result = $this->_sdk->api('/andriy.bobyk/feed', 'POST', $params);

//		var_dump($result); exit;

		return true;
	}


}